package com.todo.user.infrastructure.repository.impl;

import com.google.common.collect.Lists;
import com.todo.common.common.enums.BizErrorCodeEnum;
import com.todo.common.common.exception.BizException;
import com.todo.user.infrastructure.entity.po.UserOperateRecordPO;
import com.todo.user.infrastructure.mapper.UserOperateRecordMapper;
import com.todo.user.infrastructure.repository.UserOperateRecordRepository;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

/**
 * (UserOperateRecord)表服务实现类
 *
 * @author zhangwenxiang
 * @since 2024-03-04 21:10:04
 */
@Repository("userOperateRecordRepository")
public class UserOperateRecordRepositoryImpl implements UserOperateRecordRepository {
    @Resource
    private UserOperateRecordMapper userOperateRecordMapper;


    @Override
    public Boolean removeUserOperateRecordPOById(Long id) {
        if (id == null || id < 0) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        return userOperateRecordMapper.removeUserOperateRecordPOById(id) > 0;
    }

    @Override
    public UserOperateRecordPO queryUserOperateRecordPOById(Long id) {
        if (id == null || id < 0) {
            return null;
        }
        return userOperateRecordMapper.queryUserOperateRecordPOById(id);
    }

    @Override
    public Boolean insertUserOperateRecordPO(UserOperateRecordPO userOperateRecordPO) {
        if (userOperateRecordPO == null) {
            throw new BizException(BizErrorCodeEnum.PARAM_ERROR);
        }
        if (userOperateRecordPO.getUserId() == null || userOperateRecordPO.getOperateType() == null || userOperateRecordPO.getOperateResult() == null) {
            return false;
        }
        return userOperateRecordMapper.insertUserOperateRecordPO(userOperateRecordPO) > 0;
    }

    @Override
    public List<UserOperateRecordPO> queryUserOperateRecordPOByUserId(Long userId) {
        if (userId == null || userId < 0) {
            return Lists.newArrayList();
        }
        return userOperateRecordMapper.queryUserOperateRecordPOByUserId(userId);
    }
}
